Automatic Vertical-Database Design

ABSTRACT

An automatic physical-layout designer for a database-management system determines the database&#39;s physical layout from a set of training queries, the database&#39;s logical design, and a parameter k that indicates how many storage nodes can be lost without losing access to any of the data. The designer lays the database out as a column store such that the stored columns constitute redundant projections on the system&#39;s different storage nodes. It repeatedly identifies a projection, whose addition to the design will result in the greatest performance improvement for the training queries. In doing so, it takes into account the different compression formats to which the different projections lend themselves. When a projection has been identified as one to be added, it is added on one node, and k projections having the same columns are added to other nodes. The designer continues thus adding projections until a space budget has been reached.

BACKGROUND OF THE INVENTION

1. Field of the Invention

The present invention is directed to automatic physical-database design.

2. Background Information

One of the primary features of a relational database management system (DBMS) that distinguishes it from its predecessors (network and hierarchical data management systems) is the idea of “data independence.” Data independence separates the logical view of data (the logical layer) from its physical representation (the physical layer).

The benefits of data independence include ease of use (the logical layer acts as a user-friendly abstraction of the physical layer) and adaptivity (modifications at the physical layer, such as adding an index, can be made without breaking preexisting queries or designs at the logical layer).

In contrast to physical database design, with which the present invention is primarily concerned, the primary function of logical database design is to define a database schema in accordance with which the data to be managed are partitioned into a set of tables (or relations) whose attributes (or columns) the schema defines. An entity-relationship diagram is one tool that that assists with this process. A more formal approach involves normalization: an incremental process that first requires creating a “universal relation” that contains all attributes of all data, and then using functional dependencies to drive the gradual decomposition of this table into smaller (i.e., fewer-column) tables, stopping once the set of tables produced satisfies some set of constraints (a normal form). As an example, a set of tables is in Boyce-Codd normal form (BCNF) if every table, T, has the property that every functional dependency,

A₁→A₂

consisting solely of columns found in T has A₁ as a key (i.e., if A₁ functionally determines A₂, it functionally determines all columns in T).

The goal of normalization is to produce a logical design that is complete while guarding against inconsistency errors. A logical design is complete if it is always possible to faithfully reproduce the universal relation from the relations in the decomposition by using a single query. Inconsistency errors are prevented by ensuring that a given attribute appears only in a table whose key functionally determines it.

The present invention is concerned not so much with such logical-design elements as it is with physical database design, which affects how much storage space the data require and how quickly they can be updated and retrieved. The physical-database-design task involves balancing the competing efficiency concerns of data retrieval and data updates. The tasks related to physical database design include:

-   -   (a) Clustering: What relations and segments are stored on which         sites?     -   (b) Index Construction: Which tables should be indexed and on         what fields?     -   (c) Materialized Views: What query results should be precomputed         and automatically updated as underlying relations get updated?     -   (d) High-Availability Options: Should crash recovery be enabled         by turning on logging, or by maintaining a mirror?

Although the responsibility for producing a physical database design from a logical design typically falls to a database administrator (DBA), tools have been developed to automate much of that task. One example is IBM's DB2 Design Advisor tool as described in Valentin et al., “DB2 Advisor: An Optimizer Smart Enough to Recommend Its own Indexes,” Proc. ICDE Conf. 2000, pp. 101-110, and in Zilio et al., “DB2 Design Advisor: Integrated Automatic Physical Database Design,” Proc. 30^(th) VLDB Conference, Toronto, Canada, September, 2004, pp. 1087-97. That design tool selects among candidate combinations of indexes, materialized views, partitionings, and multi-dimensional clusterings in accordance with a cost model the same as the one that the DBMS's optimizer uses when it selects among indexes in an existing physical design to implement a query.

Another example is the AutoPart tool, described in Papadomanolakis et al., “AutoPart: Automating Schema Design for Large Scientific Databases Using Data Partitioning,”Proc. 16th International Conference on Scientific and Statistical Database Management (SSDBM 2004), Santorini Island, Greece, June 2004, pp. 21-23. That tool deals particularly with partitioning. It uses a set of example queries to identify optimal vertical and horizontal partitionings: certain groups of columns are stored separately from other groups of columns (vertical partitioning), records are in some fashion assigned to categories, and the record fragments in a given vertical partitioning are stored separately in accordance with their categories (horizontal partitioning). Moreover, the AutoPart tool makes partitioning determinations separately for different categories so that the vertical partitioning used for records of one category may differ from other records' vertical partitioning.

SUMMARY OF THE INVENTION

Although these design tools do tend to reduce the effort that physical-layout design requires, we have recognized that, in the context of vertically stored databases, the database-design tool's effectiveness can be enhanced by having it compare costs that result from using different compression formats to store the same logical column. By evaluating the costs associated with different compression formats, the system can enhance the degree to which the DBMS realizes the potential that laying databases out vertically affords.

For example, consider an embodiment in which the database's physical layout is to be designed to store data redundantly among a distributed storage system's plurality of sites in such a manner as to make the data k-safe, i.e., in such a manner that all data can be recovered so long as no more than k sites are down. Suppose that this embodiment accepts as input a training set of representative queries, a space budget for every site's available disk space, the safety threshold k, and the logical relational schema whose physical layout is to be determined. Given that the design must be k-safe, the design needs to specify characteristics of at least k+1 physical versions of each logical column. For each such version of each column, this embodiment produces a directive that specifies:

-   -   the site where that version is stored,     -   the order (“sort order”) in which data appear in that version,         and     -   the compression format to be used for that version.

If the embodiment is such as to permit different physical versions of the same logical column to be stored with different compression formats, for example, it may turn out to be most effective to use, say, run-length coding on a version in which that column is sorted in accordance with its own values, arithmetic coding on a version in which that column is sorted in accordance with the values of one of the other columns, and no compression at all on a version in which that column is sorted on yet another column's values. Even if an embodiment is so designed as to constrain all versions of a given logical column to have the same compression format, the database designer's evaluation of different compression schemes for that column can result in an optimum selection of that single compression scheme.

BRIEF DESCRIPTION OF THE DRAWINGS

The invention description below refers to the accompanying drawings, of which:

FIG. 1 is a block diagram of one type of storage system in which the present invention can be practiced;

FIG. 2 is diagram showing the relationship between a logical database design and two types of physical-layout design;

FIG. 3 is a diagram that illustrates one example of run-length encoding;

FIG. 4 is a diagram that illustrates run-length encoding over “buckets”;

FIG. 5 is a diagram that illustrates bit-map encoding;

FIG. 6 is a diagram that illustrates delta encoding;

FIG. 7 is a flow chart of a physical-layout-design method that employs the present invention's teachings;

FIG. 8 is a flow chart of FIG. 7's design-initialization operation;

FIG. 9 is a diagram illustrating data generated in selecting projections to add to the database design;

FIG. 10 is a flow chart of FIG. 7's best-projection-selection operation;

FIG. 11 is a diagram that illustrates an original baseline design;

FIG. 12 is a diagram that illustrates an intermediate step in adding a projection to the original design; and

FIG. 13 is a diagram that illustrates the result of adding that projection.

DETAILED DESCRIPTION OF AN ILLUSTRATIVE EMBODIMENT

The present invention's teachings are applicable to a wide range of database systems implemented in essentially any type of computer system. But we will assume for the sake of concreteness that it is being implemented in a system of the type depicted in FIG. 1, where each of a plurality of networked computers 101 has direct access to a respective storage device 103 and communicates over a network through a network switch 105 with the other computers, through which it can indirectly obtain access to the data on those other computers' storage devices. To perform a query, a user employs terminal equipment 107 such as a keyboard and monitor coupled to one of the computers to communicate with a DBMS process that is executing on that computer. That process performs the query by accessing its own storage device 103 and/or those of other computers.

The process that responds to the query needs to know where existing data are located and new data should be stored. For this purpose it relies on a database design that in the illustrated embodiment has been generated automatically during design operations that recur so that the data's physical layout will respond to changes in the data it is to store. Ordinarily but not necessarily the computer system that performs the automatic physical-layout operation comprises one or more of the same computers 101 that execute the queries, so one or more of the storage devices 103 typically contains programming that configures one or more of the computers 101 to perform physical-layout design in the manner that we now describe.

Aspects of the present invention find particular application in systems that employ a plurality of storage “nodes,” which the network storage devices 103 exemplify, whose availabilities are to some degree independent of each other. Among the purposes of most of the present invention's embodiments will be to store data on different such nodes redundantly so that the data can be available even when not all storage nodes are. In some installations, the different nodes may simply be different physical drives in an array treated by a server's operating system as a single logical device. More typically, a storage component will be considered a different node if access to it must be obtained through a different computer. Or a storage device may be considered part of a different node only if it is powered from a different source and/or is located in a different room, a different building, or even a different city. That is, the degree of independence required before different components are considered to belong to different nodes may not be the same in all of the invention's implementations. The general concept, though, is that there must be some degree of independence between different components' availabilities if they are to be considered to belong to different nodes.

Now, although the embodiment to be described below as exemplifying the invention's teachings is intended to implement such redundancy, not all of the invention's aspects require redundant storage. But all of the invention's embodiments will employ a “column-store,” or “vertical” physical-storage design. A column store differs from the more traditional row store architecture in that data in a column store are clustered on disk (or other persistent storage) by column, rather than by row.

FIG. 2 illustrates this distinction. A logical database design usually comprises one or more conceptual tables such as FIG. 2's table 201. A table is characterized by a set of attributes, usually depicted as column headings, for which each record in the table has respective (albeit potentially empty) values. In Table 201, for instance, the attributes are Emp# (employee number), Dept (department), Room, Phone, and Age. In conventional, horizontal storage arrangements, values of a given record's successive attributes are typically stored physically adjacent to one another, as FIG. 2's depiction of row store 203 suggests. The row-store representation of the logical table stores the table contents in a single file, in which the values are stored in the following order: row 1 (Emp#), row 1 (Dept), row 1 (Room), row 1 (Phone), row 1 (Age), row 2 (Emp#) etc. In other words, the table is stored in a manner reflecting visiting the table's contents by reading each row from left to right and then moving to the next row. The order of rows can be arbitrary, or can be based on a given set of attributes, in which case the table is effectively sorted before it is stored onto disk.

Horizontal data storage has been the traditional physical-storage approach, in part because it makes initial storage of an individual record relatively fast; to store a given record usually requires access only to, say, a single disk block. But there are a great many databases in which reading occurs much more frequently than writing. For such databases, it is often better for the physical layout to be vertical, as FIG. 2's column store 205 depicts: successive storage locations are occupied by different records' values of the same attribute. Unlike row store 203, which would typically store the entire table in a single file, a column store 205 is usually implemented by storing each column in a separate file. Thus, there is a file for the Emp# column, with values appearing in order of: 1 st row, 2nd row, 3rd row etc, a file for the Dept column, with values also appearing in order of: 1 st row, 2nd row, 3rd row, and so on.

One reason why a vertical storage arrangement is preferable for data reading is that fetching the results of a query requires access to only enough, say, disk blocks to contain the values of the attributes of interest; there is no need to access enough disk blocks to contain all of the attributes of all of the records that meet the query criteria.

To appreciate another reason why “vertical,” row-store physical designs can be preferable, it helps to recall that a key design choice for both row stores and column stores is the order in which rows or columns are stored. For example, FIG. 2's table 201 may be ordered in a row store on attribute Room, in which case that table's first row (Room=101) would be followed by the third row (Room=105) followed by the second row (Room=203). The choice of sort order strongly influences both query and update performance. For example, if the table is physically sorted on Room, then queries that include predicates on Room can be evaluated without scanning the entire table, either by performing a binary search, or, more commonly, by using a sparse index that typically is placed over the sort attribute. A common choice of sort order for a table in a row store is that of its primary key, since this makes it easier to enforce key constraints during insertions and updates.

Whereas in a row store a table is typically stored in a single file, in a column store it is typically stored in several files, one per table column. This makes it possible to store some of a table's columns in one sort order and others in a different sort order. This approach gives a DBMS greater leverage in exploiting sort orders when it processes a query. Doing so requires an additional data structure (a permutation) to map a given row's value in one column to its value in a different column sorted in a different order. But note that, given two sets of columns from a table:

-   -   S₁={C₁, . . . , C_(j)}, sorted on attributes A₁, . . . , A_(n)         (written as C₁, . . . , C_(j)|A₁, . . . , A_(n)), and     -   S₂={C_(j+1), . . . , C_(k)} sorted on attributes B₁, . . . ,         B_(m) (C_(j+1), . . . , C_(k)|B₁, . . . , B_(m)),         a single permutation suffices to map all columns in S₁ to the         corresponding values from columns in S₂. S₁ and S₂ are examples         of projections: sets of columns that are sorted on the same sort         order.

Put another way, column stores offer finer-grained control of redundancy than do row stores. A column store can be arranged to replicate all of or none of a table's columns. For example, a column store can replicate (in different sort orders) only those columns that occur most often in user queries.

Another factor that contributes to efficiency in fetching data from a vertically arranged database is the fact that successive values of the same attribute—that is, successive column entries—tend to lend themselves better to data compression, so that the total storage occupied by a given attribute's values tends to be less in a vertical storage arrangement than in a horizontal arrangement. An opportunity for compression can arise, for example, when a column containing a large number of records' values of a given attribute is sorted on that attribute but the number of that attribute's possible values is small.

One way of compressing a column thus stored is to use run-length encoding, which FIG. 3 illustrates. FIG. 3's diagram 301 depicts a single column representing various values of attribute A. Although that column contains the values from eleven different records, the number of distinct attribute values is only three, so the data can be compressed into the form that diagram 303 depicts, where each row represents a (value, starting position, length) triple. In that diagram, the first row indicates that a run of the value 1 begins at the first location in the uncompressed column and continues for five rows, the second row indicates that a value-4 run begins in the sixth row and extends for three entries, and the third row represents a value-5 run beginning at the ninth row and continuing for three entries.

FIG. 4 depicts another example of run-length encoding, this one used to represent the attribute-B values in that drawing's diagram 401. The records of that diagram are sorted primarily in accordance with their attribute-A values and only secondarily in accordance with their attribute B values. In such a case, the run-length encoding could include multiple entries for the same value. For example, diagrams 403, 405, and 407 represent the run-length codes for the sub-columns, or “buckets,” of attribute-B column 409 that correspond to the attribute-A values 1, 4, and 5, respectively.

FIG. 5 depicts another type of compression, this one often being preferable for columns not sorted on those entries' values if the number of distinct possible entries is low. Diagram 501 represents an uncompressed column, where each entry may be a multi-byte value. As in the examples of FIGS. 3 and 4, the number of entries in that diagram is large in comparison with the number of different entry values. As diagram 503 indicates, such a column can be compressed into a series of bit maps, one for each distinct value. Although diagram 503 appears larger than diagram 501, each of the entries in the column that diagram 503 represents is potentially a multi-byte value, whereas each bit-map entry is only a single bit. Each row in diagram 503 represents one of the four possible values that column 503 contains, and each column represents one of the entries. For example, diagram 503's second row represents the value 2, so the fact that that row contains only a single 1, namely, in its fifth-column entry, indicates that the only entry in column 501 whose value is 2 is the fifth one.

FIG. 6 depicts yet another encoding example, this one being well suited to columns that are sorted on their values and the number of such values is not significantly smaller than the number of column entries. In such column versions, the differences between successive records' values tend to be relatively small in comparison with the values themselves, and the FIG. 6 encoding scheme takes advantage of this feature. In FIG. 6, diagram 601 represents the uncompressed column, and diagram 603 represents the compressed version. Diagram 603's first entry is identical to diagram 601's, but diagram 603's second entry represents the difference between diagram 601's second entry and the immediately preceding, first entry, and all of diagram 603's remaining entries similarly represent the differences between the corresponding diagram-601 entries and the entries that respectively precede them.

We have chosen the run-length, bit map, and delta encoding techniques of FIGS. 3, 4, 5, and 6 as examples because they lend themselves most readily to illustration. However, embodiments of the present invention may use any other compression technique known to those skilled in the art. Examples are Lempel-Ziv and entropy techniques, such as Huffman encoding, arithmetic encoding, enumerative encoding, etc.

We now turn to the overall task that the illustrated embodiment performs. From time to time during a database's use, the database-management system will consider the question of what the system's physical layout should be. The input to the system's automatic physical-layout designer includes at the very least the database's logical design. Specifically, it includes a list of base tables and, for each base table, a list of attributes whose values that table's various columns are to contain, and usually the data types that are to be used to represent those values. Also, the logical design may specify the key attribute or attributes, i.e., the attribute or combination of attributes of which no two records are permitted to have the same values. In an employee table, for example, in which each record represents a different employee, the employee number will typically be the key attribute.

In some cases, the database's description will also include some statistical information either known a priori or learned through database use. This would almost always include at least how many records (“rows”) the system contains for each logical table. It may also indicate whether a given attribute has relatively few different values, etc. Another input to the database designer will be a set of training queries, typically but not necessarily ones that have been submitted previously to some version of the database whose physical layout is being designed (or re-designed). The designer will have as a goal to arrive at a physical layout that in some sense optimizes database operations for such queries.

The physical-layout designer also needs to know how much storage space is available to contain the database as well as how much storage the data currently occupy. Moreover, the illustrated embodiment, which is intended to produce designs in which storage is redundant, needs to know the number of independent storage nodes and their capacities. It additionally takes as an input parameter the number, which we refer to as k, of nodes whose simultaneous lack of availability the resultant design should be able to tolerate and still accord access to all data.

From this input information, the database designer determines, for each column in the database's logical design, the nodes where versions of that column will be stored and those versions' respective sort orders. The illustrative embodiment also chooses a compression format for each column version.

The procedure that the illustrated embodiment follows in doing this is to build the physical design by incrementally adding projections in a manner that will be described below. Again, the physical layout is that of a column store, and a given projection's different columns will typically—although not necessarily—be stored in separate respective files, but the illustrated embodiment nonetheless treats the projection as a unit for physical-design purposes. (As will be seen below, not every embodiment will store all of a given projection on a single node, but it simplifies the discussion to assume initially that the illustrated embodiment is one that does.)

As will now will be explained, the database designer identifies successive table projections that will achieve the greatest improvement in training-query performance. For each projection thus identified, it decides upon a node where that projection is to be stored, and it additionally specifies k further projections, all of which contain the same columns in potentially different sort orders, and these further projections will be stored on different other nodes in order to implement the “k-safety” constraint, i.e., the requirement that all data remain available so long as no more than k nodes are down.

FIG. 7 illustrates the algorithm that the illustrated embodiment employs to implement this approach. Block 701 represents performing an initialization operation, which FIG. 8 depicts. As FIG. 8's block 801 indicates, the first operation is to generate for each base table a “super-projection,” which is a projection that contains the data from all of that table's columns. The illustrated embodiment generates k+1 super-projections for each table and, as blocks 803 and 805 indicate, disperse each logical table's k+1 super-projections among k+1 different nodes. We will call the set of projections produced in this step the completers since they represent a default, complete design. In others of the invention's embodiments, it may be that not every completer is an individual base table's super-projection but is instead, say, a join of such tables. In any event, the completers together contain at least k+1 copies of all the data, and the remainder of the operation refines this design.

To that end, the system assigns to each of the design queries an estimate of the cost of executing such a query on the initial design. In most respects, the way in which the system determines such costs is not critical to the invention, and most embodiments will employ an approach that is based to a greater or lesser degree on the approach used by that database management system's “optimizer.” The optimizer is the database management system's component that determines how a query is to be implemented. All database-management systems translate queries into algorithmic access plans that get compiled or interpreted into the code whose execution fetches the data that the query specifies. The process of translating a query into an access plan is called query optimization, and the most common paradigm for query optimization is cost-based query optimization.

Given a query q, cost-based query optimization follows three steps to produce an access plan for q. First, the optimizer applies some heuristics to generate a set of candidate access plans, each of which could be used to evaluate q. Next, a “cost model” is used to estimate the cost of each candidate access plan. A cost model is a set of formulas that rely on statistical information about data contained in the database to predict the cost of an access-plan operation. Typical statistics that determine cost include the relation's cardinality, a given attribute's range and distribution, and how large any indexes over a table's attributes are. Costs are sometimes measured in estimated time to evaluate the query or in a more coarse-grained quantity, such as the estimated number of disk I/O's required to evaluate the query. Finally, the optimizer bases its choice among the candidate access plans on their estimated costs.

The cost estimation represented by FIG. 7's block 703 will likely be based on the cost model that its target database-management system's optimizer uses. In principle, this is not necessary; any cost model that maps an access plan to some numeric score can be “plugged into” the illustrated designer although unexpected results could occur if the designer's cost model does not at least agree with the optimizer's assessment of which plan's cost is greater. But there is one factor that is of importance to certain of the invention's aspects. In a system that uses column stores that store overlapping projections in different sort orders, the sort order in which columns are stored heavily influences the cost of evaluating the query. There are two reasons for this. One, of course, is that a query that uses the values of a given column's attributes in a predicate will tend to be executed most efficiently on a physical projection (“materialized view”) that is sorted in accordance with that column's values; the only values the system needs to access are those that correspond to the specified value or range. The other reason, which we have recognized as being particularly important in column stores for access-plan formulation and consequently for physical-layout design, is that, as explained above, different sort orders lend themselves to different compression formats, and an appropriate compression scheme can greatly reduce a given query's I/O cost—which in many situations dwarfs the cost of (possibly decompressing and) inspecting the retrieved values. Therefore, although a wide variety of cost models can be used in embodiments of the present invention, it is preferable that the cost model employed be one that takes into account the cost impacts of different compression formats.

The result of this initial cost determination can be represented by FIG. 9's table 901. Each row in that table represents one or more queries in the training set, the number of queries represented by a given row being represented by the “weight” entry. There are two reasons why a single row may represent more than one query. The first is that some queries may in fact be identical, so their costs are necessarily the same. The second reason is that other queries, although not identical, are considered the same by the cost model that the particular embodiment employs.

In the illustrated embodiment, for example, the input to the cost model for a given query would be not be the whole query but only a set of relevant characteristics. Specifically, a query is represented as a set of pairs that contains as many pairs as there are attributes used by the query. Each pair has the form (Attribute_Name, Usage) where Usage is an indicator of how the attribute is used (e.g., equalityPred, rangePred, output, GroupBy). Each attribute also has a known cardinality (i.e., few/many) that can be looked up in the system catalog. From the point of view of the cost model, the form of the query is more important than the specifics; the model may ignore constants, for example. So a query representation for Q_(i) might be Q_(i)={(A, equalityPred), (B, equalityPred), (D, rangePred), (E, rangePred)} to indicate that Q_(i) includes equality predicates based on attributes A and B and range predicates based on attributes D and E, and the representation may additionally include a notation that, say, A is few-valued, B few-valued, D many-valued, and E few-valued. In a training set of tens of thousands of queries, it is likely that many queries would have identical representations.

With the baseline cost of the training inquiries thus computed, the routine proceeds to the operation represented by FIG. 7's block 705, in which it computes, for various projections not yet in the current physical design, what various queries would cost if the design included those projections. One approach to doing this does not limit the projections being considered to the base tables' columns; they can extend to projections of tables derived by, e.g., joins of base tables. So, in determining what the cost of executing a query would be if a projection having a given sort order were available, the system assumes that the projection having that sort order is the projection of whatever base table or join thereof that has all the columns those queries require. (We refer to such projections of derived tables as pre-joined projections.) For inclusion in the design, that is, the algorithm considers projections of the form A₁, . . . , A_(m)|A₁, . . . , A_(k), where A₁, . . . , A_(m) comprise all attributes used by a query and A₁, . . . , A_(k) comprise a “reasonable” sort order for the projection.

Reasonable sort order here means a small subset of all possible sort orders. Compound sort keys that have more than two or three components are not usually useful. As can be appreciated by reference to FIG. 4's diagram 401, each value of one constituent attribute in a compound sort key can be though of as creating a bucket (i.e., grouping of values) in the next-most-significant constituent attribute. The number of buckets grows as the product of the cardinalities of the columns. Once there are more than, say, 500 buckets, the advantage of the compound sort order begins to disappear.

The cost of evaluating a query will not be the same for every reasonable sort order. So operation 705 results in a respective vector of costs for each query, each slot in the vector containing the cost of executing that query on a projection having a corresponding sort order. As was stated above, the system preferably arrives at these costs by taking the different resultant compression formats into account.

The particular approach to taking compression technique into account is not critical. For the sake of concreteness, though, we will assume that the illustrated embodiment chooses compression techniques in accordance with the following simple rule. A column that is sorted in accordance with its own values will be compressed by run-length encoding if it is few-valued and by delta encoding if it is many valued, and other columns will be encoded by bit maps if they are few-valued and by Lempel-Ziv encoding if they are many-valued. Also for the sake of concreteness, we will assume that it estimates the space occupied by the column to be a single block if it is run-length encoded, while columns compressed in accordance with bitmap, delta, and Lempel-Ziv encoding are respectively estimated to occupy twenty-five, fifty, and seventy-five percent of what they would if they were not compressed.

The cost model can use such assumptions in various ways. One workable query-cost model counts the number of disk-block accesses required to process the query. Although such determinations can be based on the queries' selectivities, our preference is to give greater priority to sort orders (including compound sort orders).

As was stated above, the result of computing the costs of a query for different sort orders is a vector of costs that includes a slot for each of its reasonable sort orders. The collection of all such vectors for all queries can be thought of as a table, which FIG. 9's table 902 represents, that has one row for each query and one column for each reasonable sort order. Let us call this table the Query Costing Table (QCT). There will be a large number of NULLs in each row of the QCT since most of the possible sort orders are reasonable for only a fraction of the training queries.

Each of that table's columns can be thought of in several ways. First, each represents a sort order. Second, each represents a physical projection of the database, the projection having the specified sort order and including the values of some (initially undetermined) set of attributes. Third, since the physical design being determined is vertical, each table represents a set of physical column versions, which set includes a single respective physical column version for each logical column in an (again, as-yet-undetermined) set thereof. Each of those physical column versions in a set represented by a given one of the table's columns is characterized by the same sort order, a different database attribute, and, since in the illustrated embodiment the combination of attribute and sort order determines compression format, a respective compression format (which format could be no compression at all, although in the illustrated embodiment it never is). So, by making that list of sort orders, the system has in effect made a list of physical column versions, and at least some of the listed versions of the same logical column differ from one another not only by sort order but also by compression format.

In an operation represented by FIG. 7's block 707 and depicted in more detail in FIG. 10, the physical-layout designer next picks the best projection to add to the current design. To do so, it computes some additional statistics on the QCT. As block 1001 indicates, it determines, for each of the cost cells in FIG. 9's table 902, an improvement over the baseline cost for that query, i.e. over the cost under the current design. FIG. 9's table 903 shows these improvement values after slashes in the cost cells; in the entry for Q, and sort order F, for example, the entry after the slash indicates that, if a projection having all the columns Q₁ needs and sorted on F were added to the physical-layout design, the improvement in query Q₁'s execution cost would be 20.6.

As FIG. 10's block 1003 indicates, the illustrated embodiment then compares these improvement to an Improvement Threshold (IT), which is the minimum improvement that a sort order must provide a query in order for that query to be considered in determining which columns need to be in the candidate projection that has that sort order. Suppose that the IT is 10.0 in the example. As FIG. 9's table 903 indicates, the F-sort-order entries for Q₁ and Q_(20,000) exceed that threshold and thus are candidates for use in determining the columns to include in a projection having sort order of F. Call any such query a candidate query. As FIG. 10's block 1005 indicates, the system then, for each sort order, adds together the improvements for all of that sort order's candidate queries. The “Total Improvement” row in FIG. 9's table 903 represents these results.

At this point in the process, there has been identified for each sort order the set of queries whose performance would be improved by at least IT if projection of that sort order were added to the design. From that set of queries, the illustrated embodiment determines what columns a projection having that sort order would need to include to provide such improvements, and, as FIG. 11's block 1007 indicates, it estimates the space each such potential projection would require. The illustrated embodiment does this by applying a simple space model that takes compression format into account in the manner mentioned above. The “Space” row in FIG. 9's table 903 represents the resultant space estimates. As FIG. 10's block 1009 indicates, the space value is used to compute the ratio of total improvement to space for each such projection. The “I/S” row in Table 903 represents those ratios. FIG. 10's block 1011 represents choosing for inclusion in the design the potential projection having the highest such ratio. In the FIG. 9 example, the highest ratio is associated with sort order AF, so the potential projection having that sort order is the one chosen as the output of FIG. 7's operation 707.

As FIG. 7's block 708 indicates, some embodiments may refrain from adding a projection to the design if that ratio is not great enough to justify changing the design. The assessment of what is “great enough” may, for example, be based on whether the resultant increase in access performance justifies the additional cost of updating that adding a projection exacts. Even if the ratio is great enough, moreover, the selected projection is added to the design only if that can be done consistently with k-safety without violating the space budget. So the system performs an operation represented by FIG. 7's block 709, in which it develops a proposed new design based on the selected projection in order to make that determination.

To give an example of how the illustrated embodiment performs that task, we will assume for the sake of simplicity that the base logical design consists of only a single table, that the single table is characterized by four attributes A, B, C, and D, that the physical storage system consists of only two nodes, and that the safety parameter k is unity, i.e., that the layout will be designed to preserve access to all the data if as many as one node goes down. FIG. 11 illustrates the resultant baseline design, in which each node contains a respective file for each of the logical columns: each contains a “super-projection” of the base table. We will assume that first and second nodes' projections are respectively sorted on A and C: the two baseline projections are ABCD|A and ABCD|C.

Now suppose that the projection selected by FIG. 7's operation 707 is AB|B. For k-safety purposes, that dictates adding such a projection to one of the nodes and “k-safe buddy” projections—i.e., projections including the same columns—on k other nodes. The “buddy” projections' sort orders can be the same as the sort order selected in operation 707, but it is often better if they differ. For example, their sort order can be chosen to be the ones for which the next-highest improvement-to-space ratios were computed. Since k in this example is unity, that means adding the selected projection and one k-safe buddy, as FIG. 12 illustrates.

Thus siting an additional projection on a given node will usually make the data in the same node's corresponding completer columns redundant, and some embodiments, such as the illustrated one, may elect to eliminate that redundancy by removing that completer column when such redundancy occurs. To retain the capacity to recreate the original relation, though, row-ID files will sometimes have to be provided for the resultant projections. FIG. 13 depicts the result. Although FIG. 13 shows a row-ID file for every projection, that is not usually necessary if the row ID is taken to be the row's physical position in the stored sequence.

As FIG. 7's block 711 indicates, the system determines whether that proposed design exceeds the space budget. If so, the selected projection and its k-safe buddies are not added to the design, and the design process is finished (except for one further operation, which will be described in due course). Otherwise, as block 713 indicates, that proposed design becomes the current one.

Having added a projection (and its k-safe buddies) to the design, the physical-layout designer can turn to identifying a further projection to add. Before it does so, though, the illustrated embodiment performs an operation represented by block 715, in which it removes from the training-query list the queries that were used to determine the columns for the just-added projections. This is not necessary, but we consider it beneficial, since the existing projection additions have already improved performance for those queries significantly, and removing them makes subsequent operations concentrate on improving the performance for other queries. Some further queries can also be removed from the list at this point. Suppose, for example, that the cost-computation operation had identified some training query whose cost improvement under the first selected sort order did not exceed the improvement threshold but its improvement under one of the k-safe buddies' sort orders did. If the selected projection (and therefore each of the k-safe buddies) includes all of the columns required by any such query, then they, too, can be removed from the training-query list.

With the query list thus culled and the baseline design thus updated by the selected projections' additions, the designer updates the query costs for the new baseline design, as block 717 indicates, and the operation of finding another projection to add is repeated in the manner described above until one of the criteria for termination is satisfied.

Now, the assumption was stated above that each selected projection is stored completely on a single node, and it was tacitly assumed that each of its k-safe buddies also is stored completely on a respective (but different) node. In an embodiment that operates in that fashion, the design is complete when one of the termination criteria described above is met. The system then proceeds to store the data in accordance with the design, and queries are executed on the new materialized views when that storage operation has been completed. (If the new design is being adopted during use of the database, a set of data complying with the previous design is typically retained and used to execute queries until data laid out in accordance with the new design are all in place.)

However, there are reasons why some embodiments may instead divide a projection's data among a plurality of nodes. For example, each storage device in a system of the type that FIG. 1 depicts is directly accessible only by a single respective different computer, and it is often preferable for more than one computer to be executing different parts of the same query in parallel. In such a situation, it is also desirable if, although all parallel-operating computers should operate on the same physical projection, they operate predominantly only on the data that reside in the respective, different storage devices to which those computers have direct access. This can be accomplished only if that projection's data are divided among those different storage devices.

So some embodiments will partition projections horizontally for the purpose of spreading the data out across multiple nodes. (The number of nodes among which a given projection is to be divided may, for example, have been set as a parameter when the automatic database designer was first being installed, or it may, say, be inferred in accordance with some rule from the host system's physical configuration.) We use the term segmentation to refer to such horizontal partitioning. Although such segmentation can be done at each step for that step's selected projection and its k-safe buddies, FIG. 7's block 719 depicts it as instead being performed after all the projections have been selected.

Segmentation of a given projection is performed on the basis of some column or set of columns and may be accomplished in accordance with, say, hash functions, ranges, or simple value mappings. The column on which a given projection's segmentation is based may be one that the projection does not directly include. For example, it is possible for (A B|A) to be segmented on a column, say, column C, that appears only in some other projection.

The approach that a given embodiment employs will likely depend on the relationship between the number of nodes and the number k of nodes whose unavailability needs to be tolerated. If the number of nodes is many times k, it may be practical to arrange the layout in such a manner that none of a given projection's segments resides on the same node as a segment of any of its k-safe buddies. In such cases, the columns on whose values segmentation is based will likely differ for different k-safe buddies.

More often, though, there will not be that many nodes. In such a case, some of a buddy's data have to be stored on the same node as some of the main projection's data, but it is preferable (in order to avoid unhelpful redundancy) for the “same data” (rows) not to occur on the same node. So buddy projections in such a situation are likely to be segmented identically to their main projection.

That is to say, if (A B|A) is segmented on A, then its buddy projection (A B|B) will also be segmented on A, even though it is sorted on B. This facilitates avoiding unhelpful redundancy if buddy projections' segments are staggered in a round-robin fashion such as the following.

Site A Site B Site C Projection Segment 1 Segment 2 Segment 3 Buddy Projection Segment 3 Segment 1 Segment 2

When the physical-design operation is completed, it generates an output that represents the physical design, and the management-system processes use the design to re-organize the data and execute queries on it.

By employing the present invention's teachings, a database layout can be designed automatically in a way that takes particular advantage of a column store's benefits. It thus constitutes a significant advance in the art. 

1. A computer system configured as a database designer for specifying a layout, among a plurality of storage nodes, of a database whose logical design includes at least one table of which each is organized in rows and columns, the computer system being so configured as to: A) determine a physical design for the database by: i) choosing a set of candidate sort orders; and ii) in each of a plurality of projection-selection operations: a) selecting a candidate sort order, from among the candidate sort orders not previously selected, in accordance with the cost of executing training queries on physical projections that have those candidate sort orders; b) identifying the training queries for which addition of a projection having the selected sort order results in a cost-of-execution change that meets some cost-improvement criterion; c) adding to at least one of the storage nodes of the physical design a first physical projection, thereby associated with that projection-selection operation and not similarly associated with a previous projection-selection operation, having the selected sort order and including vertically arranged versions of the logical columns that the training queries thus identified require; and d) adding at least to one different one of the storage nodes of the physical design at least a further physical projection, whose sort order differs from that of the first physical projection, whose physical column versions are versions of the logical columns of which the first physical projection's physical column versions are versions, such that all data in the first physical projection is replicated on more than one of the storage node; and B) generating an output indicative of the resultant physical design.
 2. A computer system as defined in claim 1 configured to remove from the set of training queries those identified as being the training queries for which the cost-of-execution change resulting from addition of a projection having the selected sort order meets the cost-improvement criterion.
 3. A computer system as defined in claim 1 wherein the cost-improvement criterion depends on a ratio of cost reduction to storage space.
 4. A computer system as defined in claim 1 wherein the data in some of the physical column versions are sorted in accordance with the values of another column's attribute.
 5. A computer system as defined in claim 1 wherein: A) the database designer additionally initializes the physical design by so assigning to the storage nodes of the physical design a plurality of super-projections of each of the logical design's tables as to result in a physical design in which all of the database's data remain available whenever no more than k of the nodes become unavailable, where k is some positive integer; and B) at least one said projection-selection operation further includes deleting from a said storage node of the physical design a super-projection's physical column made redundant on that storage node by the addition of that projection-selection operation's first physical projection or further physical projection.
 6. For employing a computer system to lay out among a plurality of storage nodes a database whose logical design includes at least one table of which each is organized in rows and columns, a method that comprises employing the computer system to: A) determine a physical design for the database by: i) choosing a set of candidate sort orders; and ii) in each of a plurality of projection-selection operations: a) selecting a candidate sort order, from among the candidate sort orders not previously selected, in accordance with the cost of executing training queries on physical projections that have those candidate sort orders; b) identifying the training queries for which addition of a projection having the selected sort order results in a cost-of-execution change that meets some cost-improvement criterion; c) adding to at least one of the storage nodes of the physical design a first physical projection, thereby associated with that projection-selection operation and not similarly associated with a previous projection-selection operation, having the selected sort order and including vertically arranged versions of the logical columns that the training queries thus identified require; and d) adding at least to one different one of the storage nodes of the physical design at least a further physical projection, whose sort order differs from that of the first physical projection, whose physical column versions are versions of the logical columns of which the first physical projection's physical column versions are versions, such that all data in the first physical projection is replicated on more than one of the storage node; and B) physically arrange the database's data in at least one storage device in accordance with the design thus determined.
 7. A method as defined in claim 6 comprising removing from the set of training queries those identified as being the training queries for which the cost-of-execution change resulting from addition of a projection having the selected sort order meets the cost-improvement criterion.
 8. A method as defined in claim 6 wherein the cost-improvement criterion depends on a ratio of cost reduction to storage space.
 9. A method as defined in claim 6 wherein the data in some of the physical column versions are sorted in accordance with the values of another column's attribute.
 10. A method as defined in claim 6 wherein: A) the method further comprises initializing the physical design by so assigning to the storage nodes of the physical design a plurality of super-projections of each of the logical design's tables as to result in a physical design in which all of the database's data remain available whenever no more than k of the nodes become unavailable, where k is some positive integer; and B) at least one said projection-selection operation further includes deleting from a said storage node of the physical design a super-projection's physical column made redundant on that storage node by the addition of that projection-selection operation's first physical projection or further physical projection.
 11. A storage medium containing machine instructions readable by a computer system to configure the computer system as a database designer that specifies a layout, among a plurality of storage nodes, of a database whose logical design includes at least one table of which each is organized in rows and columns, by: A) determining a physical design for the database by: i) choosing a set of candidate sort orders; and ii) in each of a plurality of projection-selection operations: a) selecting a candidate sort order, from among the candidate sort orders not previously selected, in accordance with the cost of executing training queries on physical projections that have those candidate sort orders; b) identifying the training queries for which addition of a projection having the selected sort order results in a cost-of-execution change that meets some cost-improvement criterion; c) adding to at least one of the storage nodes of the physical design a first physical projection, thereby associated with that projection-selection operation and not similarly associated with a previous projection-selection operation, having the selected sort order and including vertically arranged versions of the logical columns that the training queries thus identified require; and d) adding at least to one different one of the storage nodes of the physical design at least a further physical projection, whose sort order differs from that of the first physical projection, whose physical column versions are versions of the logical columns of which the first physical projection's physical column versions are versions, such that all data in the first physical projection is replicated on more than one of the storage node; and B) generating an output indicative of the resultant physical design.
 12. A storage medium as defined in claim 11 whose instructions configure the computer system to remove from the set of training queries those identified as being the training queries for which the cost-of-execution change resulting from addition of a projection having the selected sort order meets the cost-improvement criterion.
 13. A storage medium as defined as defined in claim 11 wherein the cost-improvement criterion depends on a ratio of cost reduction to storage space.
 14. A storage medium as defined in claim 11 wherein the data in some of the physical column versions are sorted in accordance with the values of another column's attribute.
 15. A storage medium as defined in claim 11 wherein: A) the database designer additionally initializes the physical design by so assigning to the storage nodes of the physical design a plurality of super-projections of each of the logical design's tables as to result in a physical design in which all of the database's data remain available whenever no more than k of the nodes become unavailable, where k is some positive integer; and B) at least one said projection-selection operation further includes deleting from a said storage node of the physical design a super-projection's physical column made redundant on that storage node by the addition of that projection-selection operation's first physical projection or further physical projection.
 16. A computer system configured as an automatic database designer that, for a database whose logical design includes at least one table of which each is organized in rows and columns, determines a physical design by: A) making a list that includes, for each of a plurality of the database's logical columns, a plurality of vertically arranged candidate physical versions of which at least a plurality differ at least by compression format from one another; B) for different ones of the candidate physical versions of the same logical columns, making respective cost estimates of the different costs of executing training queries on the database by using those different candidate physical versions, wherein the cost estimate depends on the candidate physical versions' compression formats; C) selecting from among the candidate physical versions in accordance with those estimates; D) including the candidate versions thus selected in a physical design; and E) generating an output indicative of the resultant physical design.
 17. A computer system as defined in claim 16 wherein the physical design so assigns the physical versions of the columns to a plurality of storage nodes that that the set of storage nodes remaining after removal of any k of the nodes contains all of the database's data, where k is a positive integer.
 18. A computer system as defined in claim 11 wherein the cost estimates are additionally based on the candidate physical versions' sort orders.
 19. For managing a database whose logical design includes at least one table of which each is organized in rows and columns, a method comprising: A) determining a physical design for the database by: i) making a list that includes, for each of a plurality of the database's logical columns, a plurality of vertically arranged candidate physical versions of which at least a plurality differ at least by compression format from one another; ii) for different ones of the candidate physical versions of the same logical columns, making respective cost estimates of the different costs of executing training queries on the database by using those different candidate physical versions, wherein the cost estimates depend on those candidate physical versions' compression formats; iii) selecting from among the candidate physical versions in accordance with those cost estimates; and iv) including the candidate column versions thus selected in a physical design; and: B) physically arranging the database's data in at least one storage device in accordance with the design thus determined.
 20. A method as defined in claim 19 wherein the physical design so assigns the physical versions of the columns to a plurality of storage nodes that that the set of storage nodes remaining after removal of any k of the nodes contains all of the database's data, where k is a positive integer.
 21. A method as defined in claim 19 wherein the cost estimates are additionally based on the candidate physical versions' sort orders.
 22. A storage medium containing instructions readable by a computer system to configure the computer system as an automatic database designer that, for a database whose logical design includes at least one table of which each is organized in rows and columns, determines a physical design by: A) making a list that includes, for each of a plurality of the database's logical columns, a plurality of vertically arranged candidate physical versions of which at least a plurality differ at least by compression format from one another; B) for different ones of the candidate physical versions of the same logical columns, making respective cost estimates of the different costs of executing training queries on the database by using those different candidate physical versions, wherein the cost estimate depends on the candidate physical versions' compression formats; C) selecting from among the candidate physical versions in accordance with those estimates; D) including the candidate versions thus selected in a physical design; and E) generating an output indicative of the resultant physical design.
 23. A storage medium as defined in claim 22 wherein the physical design so assigns the physical versions of the columns to a plurality of storage nodes that that the set of storage nodes remaining after removal of any k of the nodes contains all of the database's data, where k is a positive integer.
 24. A storage medium as defined in claim 22 wherein the cost estimates are additionally based on the candidate physical versions' sort orders.
 25. A computer system configured as an automatic database designer that, for a database whose logical design includes at least one table of which each is organized in rows and columns, specifies a physical design by: A) making a list that includes, for each of a plurality of the database's logical columns, a plurality of candidate physical versions of which at least a plurality differ at least by sort order from one another; B) for different ones of the candidate physical versions of the same logical columns, making respective cost estimates of the different costs of executing training queries on the database by using those different candidate physical versions, wherein the cost estimate depends on those different candidate physical versions' sort orders; C) selecting from among the candidate physical versions in accordance with those cost estimates; D) including the candidate physical versions thus selected in a physical design; and E) generating an output indicative of the resultant physical design.
 26. A computer system as defined in claim 25 wherein the physical design so assigns the physical versions of the columns to a plurality of storage nodes that that the set of storage nodes remaining after removal of any k of the nodes contains all of the database's data, where k is a positive integer.
 27. For employing a computer system to lay out a database whose logical design includes at least one table of which each is organized in rows and columns, a method that comprises employing the computer system to: A) make a list that includes, for each of a plurality of the database's logical columns, a plurality of candidate physical versions of which at least a plurality differ at least by sort order from one another; B) for different ones of the candidate physical versions of the same logical columns, make respective cost estimates of the different costs of executing training queries on the database by using those different candidate physical versions, wherein the cost estimate depends on those different candidate physical versions' sort orders; C) select from among the candidate physical versions in accordance with those cost estimates; D) include the candidate physical versions thus selected in a physical design; and E) physically arranging the database's data in at least one storage device in accordance with the design thus determined.
 28. A method as defined in claim 27 wherein the physical design so assigns the physical versions of the columns to a plurality of storage nodes that that the set of storage nodes remaining after removal of any k of the nodes contains all of the database's data, where k is a positive integer.
 29. A storage medium containing machine instructions readable by a computer system to configure the computer system as an automatic database designer that, for a database whose logical design includes at least one table of which each is organized in rows and columns, determines a physical design by: A) making a list that includes, for each of a plurality of the database's logical columns, a plurality of candidate physical versions of which at least a plurality differ at least by sort order from one another; B) for different ones of the candidate physical versions of the same logical columns, making respective cost estimates of the different costs of executing training queries on the database by using those different candidate physical versions, wherein the cost estimate depends on those different candidate physical versions' sort orders; C) selecting from among the candidate physical versions in accordance with those cost estimates; D) including the candidate physical versions thus selected in a physical design; and E) generating an output indicative of the resultant physical design.
 30. A storage medium as defined in claim 29 wherein the physical design so assigns the physical versions of the columns to a plurality of storage nodes that that the set of storage nodes remaining after removal of any k of the nodes contains all of the database's data, where k is a positive integer.
 31. A computer system configured as an automatic database designer that, for a database whose logical design includes at least one table of which each is organized in rows and columns, specifies a layout thereof among a plurality of storage nodes by: A) estimating the cost of executing a set of training queries and thereby, choosing a plurality of different vertically arranged physical projections of the logical columns that together contain at least k+1 copies of all the database's data, where k is a positive integer; B) assigning the physical projections thus chosen to the storage nodes in such a manner that the set of storage nodes remaining after removal of any k of the nodes contains all of the database's data; and C) generating an output representative of a physical design in which the chosen physical projections are thus assigned.
 32. For employing a computer system to specify a physical design in accordance with which to lay out among a plurality of storage nodes a database whose logical design includes at least one table of which each is organized in rows and columns, a method that comprises employing the computer system to: A) by estimating the cost of executing a set of training queries, choose a plurality of different vertically arranged physical projections of the logical columns that together contain at least k+1 copies of all the database's data, where k is a positive integer; B) assign the physical projections thus chosen to the storage nodes in such a manner that the set of storage nodes remaining after any k of the nodes is removed contains all of the database's data; and C) generate an output representative of a physical design in which the chosen physical projections are thus assigned.
 33. A storage medium containing machine instructions readable by a computer system to configure the computer system as an automatic database designer that, for a database whose logical design includes at least one table of which each is organized in rows and columns, determines a layout thereof among a plurality of storage nodes by: A) estimating the cost of executing a set of training queries and thereby choosing a plurality of different vertically arranged physical projections of the logical columns that together contain at least k+1 copies of all the database's data, where k is a positive integer; B) assigning the physical projections thus chosen to the storage nodes in such a manner that the set of storage nodes remaining after any k of the nodes is removed contains all of the database's data; and C) generating an output representative of a physical design in which the chosen physical projections are thus assigned. 